package com.singzi.javaSenior.threads.threadLocal.demo;

public class DemoSynchronized {
    private String info;

    public String getInfo() {
        return info;
    }
    private void setInfo(String content) {
        this.info = content;
    }

    public static void main(String[] args) {
        DemoSynchronized demo = new DemoSynchronized();
        Object obj = new Object();
        for (int i = 0; i < 5; i++) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    synchronized(obj){
                        demo.setInfo(Thread.currentThread().getName() + "的数据");
                        System.out.println("-----------------------");
                        System.out.println(Thread.currentThread().getName() + "--->" + demo.getInfo());
                    }

                }
            });
            thread.setName("线程" + i);
            thread.start();
        }
    }



}
